<?php
require_once("libs/dbmodel.php");

class Articulo extends DbModel {
	
	/**
	 * Obtains all product requests which apply to a seller
	 * @param $id_seller
	 * @param $categories Comma separated categories
	 * @param $locations Comma separated locations
	 * @param $with_photo (S/N/*)
	 * @param $lang
	 * @return boolean
	 */
	public function getProductRequestsBySeller($id_seller, $categories, $locations, $with_photo, $lang) {
		$sql = "SELECT a.id, a.descripcion, a.id_categoria, /*n.nombre,*/ a.con_foto, a.fecha, u.id_ubicacion, /*l.ubicacion,*/ o.nombre AS comprador
				FROM articulo a, ubicaciones_articulo u, categorias_vendedor c, usuario o/*, ubicacion l, nombre_categoria n*/
				WHERE
				  a.id = u.id_articulo
				  AND a.id_categoria = c.id_categoria
				  AND o.id = a.id_comprador
				  /*AND l.id = u.id_ubicacion
				  AND n.id_categoria = a.id_categoria
				  AND n.idioma = '$lang'*/
				  AND c.id_vendedor = $id_seller
				  AND a.id NOT IN (
				     SELECT co.id_articulo
				     FROM cotizacion co
				     WHERE co.id_vendedor = $id_seller
				     AND co.id_comprador = a.id_comprador
				  ) 
				  AND fn_get_ubicaciones_vendedor($id_seller) like '%,'||u.id_ubicacion||',%'
		";
		
		if ($categories != "*") {
			$sql = $sql . "AND ',$categories,' LIKE ('%,'||a.id_categoria||',%')
			";
		}
		
		if ($locations != "*") {
			$sql = $sql . "AND ',$locations,' LIKE ('%,'||u.id_ubicacion||',%')
			";
		}
		
		if ($with_photo != "*") {
			$sql = $sql . "AND a.con_foto = '$with_photo'
			";
		}
		
		if ($this->execQuery($sql)) {
			return true;
		} else {
			return false;
		}
	}
}

?>
